import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import Home from '../views/home/index.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: Home,
  },
  {
    path: '/products',
    name: 'products',
    component: () => import('../views/products/index.vue')
  },
  {
    path: '/design',
    name: 'design',
    component: () => import('../views/design/index.vue')
  },
  {
    path: '/templates',
    name: 'templates',
    component: () => import('../views/templates/index.vue')
  },
  {
    path: '/:pathMatch(.*)',
    name: 'notFounbd',
    component: () => import('../views/notFound/index.vue')
  }
]

const router = new VueRouter({
  routes,
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})

router.beforeEach((to, from, next) => {
  NProgress.start()
  next()
})

router.afterEach((to, from) => {
  NProgress.done()
})

export default router
